package com.haoxi.gateway.test.message;

import com.haoxi.gateway.test.SGIPConstant;
import com.haoxi.gateway.test.util.TypeConvert;

public class SGIPActiveTestRepMessage extends SGIPMessage {
    public SGIPActiveTestRepMessage(byte[] seqid, int success_Id)
            throws IllegalArgumentException {
        int len = 21;
        buf = new byte[len];
        TypeConvert.int2byte(len, buf, 0);
        TypeConvert.int2byte(SGIPConstant.ACTIVE_TEST_RESP, buf, 4);
        System.arraycopy(seqid, 0, buf, 8, 12);
        buf[20] = (byte) success_Id;

    }

    public SGIPActiveTestRepMessage(byte[] buf) throws IllegalArgumentException {
        super.buf = new byte[20];

        System.arraycopy(buf, 0, super.buf, 0, 20);
        message_Length = TypeConvert.byte2int(super.buf, 0);
        command_ID = TypeConvert.byte2int(super.buf, 4);
        src_node_Id = TypeConvert.byte2int(super.buf, 8);
        time_Stamp = TypeConvert.byte2int(super.buf, 12);
        sequence_Id = TypeConvert.byte2int(super.buf, 16);

    }

    public int getSuccessId() {
        return buf[20];
    }

    public int getSequenceId() {
        sequence_Id = TypeConvert.byte2int(buf, 16);
        return sequence_Id;
    }

    public String toString() {
        String tmpStr = "SGIP_Active_Test_REP: ";
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("Sequence_Id=")
                .append(getSequenceId())));
//        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
//                .valueOf(String.valueOf(tmpStr)))).append(",SuccessId=")
//                .append(String.valueOf(buf[20]))));
        return tmpStr;
    }

    public int getCommandId() {
        return TypeConvert.byte2int(buf, 4);

    }
}
